using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Data.Models.Mapping
{
    public class PurchaseDetailMap : EntityTypeConfiguration<PurchaseDetail>
    {
        public PurchaseDetailMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.Description)
                .HasMaxLength(1000);

            // Table & Column Mappings
            this.ToTable("PurchaseDetails");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.GoodID).HasColumnName("GoodID");
            this.Property(t => t.PurchaseID).HasColumnName("PurchaseID");
            this.Property(t => t.Quantity).HasColumnName("Quantity");
            this.Property(t => t.Price).HasColumnName("Price");
            this.Property(t => t.Discount).HasColumnName("Discount");
            this.Property(t => t.TotalMoney).HasColumnName("TotalMoney");
            this.Property(t => t.Description).HasColumnName("Description");
            this.Property(t => t.MaterialID).HasColumnName("MaterialID");
            this.Property(t => t.Price_In).HasColumnName("Price_In");

            // Relationships
            this.HasOptional(t => t.Material)
                .WithMany(t => t.PurchaseDetails)
                .HasForeignKey(d => d.MaterialID);
            this.HasRequired(t => t.Product)
                .WithMany(t => t.PurchaseDetails)
                .HasForeignKey(d => d.GoodID);
            this.HasRequired(t => t.Purchase)
                .WithMany(t => t.PurchaseDetails)
                .HasForeignKey(d => d.PurchaseID);

        }
    }
}
